import React, { useEffect, useState, useRef } from 'react'
import { useModel, history, useSearchParams } from '@umijs/max'
import { ProTable } from '@ant-design/pro-components'
import { PlusOutlined, UserOutlined } from '@ant-design/icons'
import { Button, Input, Modal, Form, InputNumber, App } from 'antd'
import styles from './Agent.less'

const agentBanner = require('@/assets/agent_top_banner.png')

export default () => {
  const { ShareAgentSignPlatformList } = useModel('Agent')
  const { message, modal } = App.useApp()

  const tableRef = useRef()

  const originColumns = [
    {
      title: '平台名称',
      dataIndex: 'platform_name',
      width: 100
    },
    {
      title: '平台联系人',
      dataIndex: 'platform_person',
      width: 80
    },
    {
      title: '签约价（元）',
      dataIndex: 'sign_price',
      width: 80
    },
    {
      title: '系统交付时间',
      dataIndex: 'system_delivery_time',
      width: 100
    },
    {
      title: '结算方式',
      dataIndex: 'settlement_method',
      width: 80
    },
    {
      title: '结算金额（元）',
      dataIndex: 'settlement_amount',
      width: 80
    },
    {
      title: '结算状态',
      dataIndex: 'settlement_status',
      width: 80,
      valueEnum: {
        1: {
          text: '待结算',
          status: 'Default'
        },
        2: {
          text: '待打款',
          status: 'Warning'
        },
        3: {
          text: '已结算',
          status: 'Success'
        }
      }
    },
    {
      title: '结算时间',
      dataIndex: 'settlement_time',
      width: 120
    },
    {
      title: '结算凭证',
      dataIndex: 'settlement_voucher_url',
      valueType: 'image',
      width: 80,
    }
  ]

  return (
    <ProTable
      headerTitle='签约平台数据'
      actionRef={tableRef}
      request={async params => {
        const res = await ShareAgentSignPlatformList({ per_page: 100, page: 1 })
        const { list, total, amount_list } = res

        list.push({
          platform_name: '总计',
          sign_price: amount_list.sign_price_sum.toFixed(2),
          settlement_amount: amount_list.settlement_amount_sum.toFixed(2)
        })
        return {
          data: list,
          success: true,
          total: total
        }
      }}
      rowKey='id'
      search={false}
      pagination={false}
      columns={originColumns}
    />
  )
}
